﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Pages_CreateUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ListUserType();
            hdnLoggedInUser.Value = Session["UserId"].ToString();
        }
    }


    private void ListUserType()
    {
        DataSet dt = new DataSet();
        dt = BusinessClass.GetUserType();
        ddlRole.DataSource = dt;
        ddlRole.DataTextField = "Value";
        ddlRole.DataValueField = "IndexKey";
        ddlRole.DataBind();
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        try
        {
            int result = 0;
            hdnUserId.Value = "0";
            result = DataAccessClass.CreateUser(txtUserName.Text, txtPassword.Text, txtName.Text, txtAddress.Text, ddlRole.SelectedValue, hdnLoggedInUser.Value, hdnUserId.Value);
            if (result > 0)
            {
                trMessage.Visible = true;
                trError.Visible = false;
            }
            else
            {
                trMessage.Visible = false;
                trError.Visible = true;
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
}